package scu.maqiang.homogenization;

import scu.maqiang.fes.FES2T31;
import scu.maqiang.mesh.*;
import scu.maqiang.numeric.MVO;
import scu.maqiang.numeric.SRMatrix;

public class PoissonCellPeriodic2DT3 {

	public static void main(String[] args) {
		long begin = System.nanoTime();
	    int N = 8;
	    double eps= 1.0 / N;

	    /*
	    Mesh2T3Generator  mgt3 = new Mesh2T3Generator();
	    Mesh2T3 cellMesh = mgt3.square2D(256, 256, T3Type.Cross2);
	    cellMesh.displayNodes();
	    cellMesh.displayElements();
	    cellMesh.displayBoundarys();
	    ScalarFunc regionCellFunc = (xy, llable, param) -> {
            return (Math.abs(xy[0] - 0.5) < 0.25 && Math.abs(xy[1] - 0.5) < 0.25)? 1.0:-1.0;
        };
	    cellMesh.setDomainLabel(regionCellFunc, null, 10);
*/
	    //cellMesh.displayElements();
//	    System.exit(0);

	    Mesh2T3 cellMesh = new Mesh2T3().readMesh("D:\\OneDrive\\FFStudy\\Homogenization\\EigenValue\\QEP\\TwoCirclesMesh.msh",
				MeshFormat.msh);
	    FES2T31 fsCell = new FES2T31(cellMesh);
	    //double[][] FOCS = new double[2][fsCell.GetNdof()];
		//double[][] SOCS = new double[4][fsCell.GetNdof()];
		double[][] D = new double[2][2];
		SOTS2DT361 ss = new SOTS2DT361(fsCell, null);
		
		//ScalarCoefFunc[] gcf = {cf};
		double[][] coef1 = {{0.001, 0}, {0, 0.001}};
		double[][] coef2 = {{1.0, 0}, {0, 1.0}};
		MatrixFunc mf = (xyz, label, param) -> label == 4? coef2 : coef1;
		//ss.KxxCellSolutionPeriodic(mf, null, FOCS, D, SOCS);
		double[][] FOCS = ss.AijFirstOrderCellSolution_PeriodicDirichletBoundary(mf, null);
		SRMatrix A = new SRMatrix(fsCell.GetNdof());
		System.out.println(MVO.toString(D));
		cellMesh.toTecplot("CellFOCS_All.dat", FOCS);
		MVO.saveArray("N1_Periodic.txt", FOCS[0]);
		MVO.saveArray("N2_Periodic.txt", FOCS[1]);
		MVO.saveArray("N1_Periodic_Bottom.txt", FOCS[2]);
		MVO.saveArray("N2_Periodic_Bottom.txt", FOCS[3]);
		MVO.saveArray("N1_Periodic_Right.txt", FOCS[4]);
		MVO.saveArray("N2_Periodic_Right.txt", FOCS[5]);
		MVO.saveArray("N1_Periodic_Top.txt", FOCS[6]);
		MVO.saveArray("N2_Periodic_Top.txt", FOCS[7]);
		MVO.saveArray("N1_Periodic_Left.txt", FOCS[8]);
		MVO.saveArray("N2_Periodic_Left.txt", FOCS[9]);
		MVO.saveArray("N1_Periodic_BottomRight.txt", FOCS[10]);
		MVO.saveArray("N2_Periodic_BottomRight.txt", FOCS[11]);
		MVO.saveArray("N1_Periodic_TopRight.txt", FOCS[16]);
		MVO.saveArray("N2_Periodic_TopRight.txt", FOCS[17]);
		MVO.saveArray("N1_Periodic_TopLeft.txt", FOCS[20]);
		MVO.saveArray("N2_Periodic_TopLeft.txt", FOCS[21]);
		MVO.saveArray("N1_Periodic_BottomLeft.txt", FOCS[14]);
		MVO.saveArray("N2_Periodic_BottomLeft.txt", FOCS[15]);
		cellMesh.toTecplot("CellSOCS_Periodic.dat", FOCS);
	}

}
